﻿#include "QButtonBase.h"

QCOMMWIDGETS_BEGIN_NAMESPACE

QTextButton::QTextButton(const QString str, QWidget *parent, const QColor colorNormal, const QColor colorHover, const QColor colorPressed)
    : QToolButton(parent)
{
    this->setText(str);
    QString strStyleSheet;
    strStyleSheet.sprintf("QToolButton{border: none; color:rgb(%d,%d,%d);} QToolButton::hover{color:rgb(%d,%d,%d);} QToolButton::pressed{color:rgb(%d,%d,%d);}",
                          colorNormal.red(), colorNormal.green(), colorNormal.blue(),
                          colorHover.red(), colorHover.green(), colorHover.blue(),
                          colorPressed.red(), colorPressed.green(), colorPressed.blue());
    this->setStyleSheet(strStyleSheet);
    this->setAutoRaise(true);
}

QTextButton::~QTextButton()
{

}

void QTextButton::mousePressEvent(QMouseEvent *e)
{
    if (hitButton(e->pos())){  // 按下时候光标在按钮区域
        m_bPressed = true;
    }
    QToolButton::mousePressEvent(e);   // 继续默认处理
}

void QTextButton::mouseReleaseEvent(QMouseEvent *e)
{
    if (m_bPressed && hitButton(e->pos())){  // 松开时候光标仍在按钮区域
        emit signClicked();
    }
    m_bPressed = false;
    QToolButton::mouseReleaseEvent(e);   // 继续默认处理
}

QCOMMWIDGETS_END_NAMESPACE
